export const img_root = 'http://img.rcglife.com/';

export function handPic(url, size) {
    let _url;
    if (url) {
        _url = img_root + url + '-r' + (parseInt(size) * 100);
    }
    return _url;
};

export function timeFormat(time, format = "hi") {
    let date = new Date(parseInt(time) * 1000),
        minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    switch (format) {
        case 'hi':
            return date.getHours() + ":" + minute;
            break;
        case 'ymd':
            return date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate();
            break;
    }
};

export function getUrl(tip,obj){
    let url;
    switch(tip){
        case 'goods_detail':
            url = `/pages/goods_details/goods_details?gc_id=${obj.gc_id}`;
        break;
        case 'cart':
            url = `/pages/cart/cart?type=${obj.ctype}`;
        break;
        case 'pay':
            url = `/pages/payment/payment?type=${obj.ctype}`;
        break;
        case 'menu':
            url = `/pages/mine/order_list/order_list?type=${obj.type}`;
        break;
        case 'comment':
            url = `/pages/mine/evaluation/evaluation?id=${obj.id}`;
        break;
        case 'cate':
            url = `/pages/special/special?cateid=${obj.cateid}`;
        break;
        case 'order_detail':
            url = `/pages/mine/order_details/order_details?order_sn=${obj.order_sn}`;
        break;
    }
    return url;
}

export function error(msg){
    wx.showToast({
        title: msg,
        image: '/img/public/error.png',
        mask:true
    })
}